<?php

namespace app\admin\controller;

use app\common\wechat\TPWechat;

class WechatController
{
    public function index()
    {
        echo 'wechat';
    }

    public function wechatServer()
    {
        $weObj = new TPWechat(config('wechat'));
        $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        $type = $weObj->getRev()->getRevType();
        switch ($type) {
            case TPWechat::MSGTYPE_TEXT:
                // $weObj->text("消息回复测试1111")->reply();
                break;
            case TPWechat::MSGTYPE_EVENT:
                $weObj->text("欢迎关注,兑换蟹券,请点击下方菜单!")->reply();
                break;
            case TPWechat::MSGTYPE_IMAGE:
                break;
            default:
                $weObj->text("help info")->reply();
        }

    }

    public function createMenu()
    {
        $weObj = new TPWechat(config('wechat'));
        // $weObj->valid(); //明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        if($weObj->createMenu(config('wechat_menu'))){
            echo 'OK';
        }else{
            echo $weObj->errCode;
            echo "<br>";
            echo $weObj->errMsg;
        }
        
    }

}
